<?php
    /*
        $content['table']: contain table name
        $content['title']: contain title of table
        $content['columns_title']: contain title of field 
        $content['page_size']: size of page
    */
    $CI=& get_instance();
    $CI->load->model('dashboard/backend_model','be');
    $CI->load->helper('common_function');
?>
<div class="title">
    <h2> 
        <?=$content['title']?>
    </h2>
</div>
<div class="filter">
</div>
<div class="view-ifo">
    <table class="tbl-view" cellspacing="2">
    <?php
        if(isset($content['columns_title']))
        {
            //view title
            echo '<tr>';
            foreach($content['columns_title'] as $title)
            {
                echo '<th>';
                echo $title;
                echo '</th>';
            }
            echo '<th>Edit</th>';
            echo '<th>Delete</th>';
            echo '</tr>';
            
            //get records from database
            $i=1;
            foreach($CI->be->get_data_from_table($content['table'],null) as $row)
            {
                //view record
                if($i % 2 == 1)
                {
                    echo '<tr class="odd">';
                }
                else
                {
                    echo '<tr class="even">';
                }
                // variable container id of row
                $id=-1;
                foreach($content['columns_title'] as $k => $v)
                {
                    if($k =='id')
                    {
                        $id = $row[$k];
                    }
                    echo '<td>';
                    if(substr($k,0,5)=='image')
                    {
                        echo '<img class="img-view" src="'.base_url('data/images').'/'.$row[$k].'" onerror="defaultimg(this)"/>';
                    }
                    else if(substr($k,0,2)=='is')  //if field container 'is' prefix then show status else show text
                    {
                        //check status
                        if($row[$k]==1)
                        {
                             echo '<a href="'.site_url('dashboard/backend/change_status').'/'.$content['table'].'/'.$id.'/'.$k.'/0" class="btaction" title="true">
                                <img src="'.base_url().'images/backend/tick.png" onerror="defaultimg(this)"/>
                              </a>';
                        }
                        else
                        {
                             echo '<a href="'.site_url('dashboard/backend/change_status').'/'.$content['table'].'/'.$id.'/'.$k.'/1" class="btaction" title="false">
                                <img src="'.base_url().'images/backend/negative.png" onerror="defaultimg(this)"/>
                              </a>';
                        }
                    }
                    else
                    {
                         if(substr($k,0,5)=='price' || $k=='total_payment') //is price field, yes or no?
                         {
                            echo format_money($row[$k]);
                         }
                         else
                         {
                            echo $row[$k];
                         }
                    }
                    echo '</td>';
                }
                echo '<td>';
                echo '<a href="'.site_url('dashboard/backend/edit').'/'.$content['table'].'/'.$id.'" class="btaction" title="edit">
                        <img src="'.base_url().'images/backend/edit.png" onerror="defaultimg(this)"/>
                      </a>';
                echo '</td>';
                echo '<td>';
                echo '<a href="'.site_url('dashboard/backend/delete_record').'/'.$content['table'].'/'.$id.'" onclick="return confirm(\'Are you sure you want to delete?\');" class="btaction" title="delete">
                        <img src="'.base_url().'images/backend/remove.png" onerror="defaultimg(this)"/>
                      </a>';
                echo '</td>';
                echo '</tr>';
                $i++;
            }
        }
    ?>
     </table>
</div>
<div class="paging">
    <?=isset($content['page_size'])?$content['page_size']:''?>
    <?php
        $CI->load->view('dashboard/templates/paging');
    ?>
</div>